-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[WIP] ABI Lowering Library #140112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[WIP] ABI Lowering Library #140112
Conversation
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
43855e6 to
114cab7
Compare
4410289 to
2832642
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing still missing here is handling for C++ structs with base classes.
329556a to
0f045da
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having both FunctionABIInfo and ABIFunctionInfo is pretty confusing... do these need to be separate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
um, I've renamed it for the time being - if I feel it doesn't serve a purpose in a few days I'll put it somewhere else
268c470 to
690068f
Compare
llvm/lib/ABI/ABITypeMapper.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... this is tricky. I'm not entirely sure what to do here. For the purpose of mapping ABIArgInfo, we should never encounter unions. For the struct case, things are tricky. Mostly, I believe we just want LLVM structs as a means of holding multiple values. E.g. a StructType for Direct arguments will normally get unpacked into individual arguments. In this case, we really don't want any kind of padding fillers in it. I think the only case that cares about that is CoerceAndExpand, which has two struct types, one just with the elements (which will be passed as separate arguments) and one that has the actual layout (with correct alignment etc).
This kind of makes me wonder whether it would make sense to start by storing llvm types in ABIArgInfo to match what clang currently does. abi::Type is conceptually nicer, but also not quite the right representation for everything (e.g. because it can't really represent the "struct without layout" case well).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should never encounter unions
Oh yeah! My bad...
Also I'm assuming both times you referred to ABIArgInfo you were talking about abi::ABIArgInfo and not codegen::ABIArgInfo (should probably name that something slightly different sorry).
Given that assumption - I really don't think we need to bring llvm::Type into the library as the struct without layout case can be added to the ABI typesystem itself (add another type of abi::StructPacking or decide whether we need padding while converting). But agreed a lot of cleanup to be done here, I'll keep it in mind while writing the x86 target.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I'm assuming both times you referred to
ABIArgInfoyou were talking aboutabi::ABIArgInfoand notcodegen::ABIArgInfo(should probably name that something slightly different sorry).
Yeah, I mean abi::ABIArgInfo. Btw, I wonder whether we should call these abi::ArgInfo etc, given that we already have abi in the namespace name...
Given that assumption - I really don't think we need to bring
llvm::Typeinto the library as the struct without layout case can be added to the ABI typesystem itself (add another type ofabi::StructPackingor decide whether we need padding while converting). But agreed a lot of cleanup to be done here, I'll keep it in mind while writing the x86 target.
Yeah, this is an option. I was mostly thinking about using llvm::Type as the path of least resistance to clang integration...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
um, I've renamed it for the time being - if I feel it doesn't serve a purpose in a few days I'll put it somewhere else
llvm/lib/ABI/ABITypeMapper.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should never encounter unions
Oh yeah! My bad...
Also I'm assuming both times you referred to ABIArgInfo you were talking about abi::ABIArgInfo and not codegen::ABIArgInfo (should probably name that something slightly different sorry).
Given that assumption - I really don't think we need to bring llvm::Type into the library as the struct without layout case can be added to the ABI typesystem itself (add another type of abi::StructPacking or decide whether we need padding while converting). But agreed a lot of cleanup to be done here, I'll keep it in mind while writing the x86 target.
e91424c to
a48eefc
Compare
llvm/lib/ABI/Targets/X86.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A note for the future: We probably need to do something to avoid leaking memory from these temporary types. We can probably checkpoint the type arena before computing ABIArgInfo and then restore the checkpoint once it's no longer needed.
b949795 to
565bf3b
Compare
90500f7 to
7097478
Compare
| bool CanPassInRegisters; | ||
| bool IsCoercedRecord; | ||
| bool IsUnion; | ||
| bool IsTransparent; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use something like LLVM_PREFERRED_TYPE(bool) unsigned IsTransparent : 1; etc to pack these into bits.
| bool HasNonTrivialCopyConstructor; | ||
| bool HasNonTrivialDestructor; | ||
| bool HasFlexibleArrayMember; | ||
| bool HasUnalignedFields; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell, this HasUnalignedFields property is unused.
| if (RT->isPolymorphic() || RT->hasNonTrivialCopyConstructor() || | ||
| RT->hasNonTrivialDestructor() || RT->hasFlexibleArrayMember() || | ||
| RT->getNumVirtualBaseClasses() != 0) | ||
| return nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does this condition come from? Comparing to
| const Type *CodeGen::isSingleElementStruct(QualType T, ASTContext &Context) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't it need to account for VTable Pointers, and other C++ ABI affecting factors like dtors. Like:
struct test {
virtual void foo();
int x;
};Was just a hunch, I could remove it if its trivial and get rid of those flags from the typesystem in that case...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That does make sense, but what I don't really get is why these things aren't checked in the existing Clang code. I think maybe the assumption is that this has already been handled previously by getRecordArgABI(), so records like that won't reach to this point? (In which case I guess the main needed property is CanPassInRegisters?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm maybe... I'll give it a try
Project report
This PR details the implementation details of the proposed ABI lowering library.